In computer science, a dispatch table is a table of pointers or to functions or methods. Use of such a table is a common technique when implementing late binding in object-oriented programming.
sub say_goodbye {
my %dispatch = (
"-h" => sub { return "hello\n"; },
"-g" => \&say_goodbye
);
return "goodbye\n";
}
my $sub = $dispatch{$ARGV0};
print $sub ? $sub->() : "unknown argument\n";
Running this Perl program as perl greet -h will produce "hello", and running it as perl greet -g will produce "goodbye".
doThisThing() { /* behavior */ }, doThatThing() { /* behavior */ }, doThisOtherThing() { /* behavior */ }, default() { /* behavior */ }};
function doSomething(doWhat) {
const thingToDo = Object.hasOwn(thingsWeCanDo, doWhat) ? doWhat : "default"; return thingsWeCanDo[thingToDo]();}
|
|